package com.icloud.admin.webservice;


import com.icloud.admin.webservice.service.PermissionService;

import com.icloud.api.vo.authority.PermissionInfo;
import com.icloud.api.vo.user.UserInfo;
import com.icloud.common.InvokeResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ${DESCRIPTION}
 *
 * @author wanghaobin
 * @create 2017-06-21 8:15
 */
@RestController
@RequestMapping("api")
public class UserRest {
    @Autowired
    private PermissionService permissionService;

    @RequestMapping(value = "/user/username/{username}", method = RequestMethod.GET, produces = "application/json")
    public InvokeResult getUserByUsername(@PathVariable("username") String username) {
        return new InvokeResult<UserInfo>(permissionService.getUserByUsername(username));
    }

    @RequestMapping(value = "/permissions", method = RequestMethod.GET)
    public InvokeResult<List<PermissionInfo>> getAllPermission() {
        return new InvokeResult<List<PermissionInfo>>(permissionService.getAllPermission());
    }


    @RequestMapping(value = "/user/un/{username}/permissions", method = RequestMethod.GET)
    public InvokeResult<List<PermissionInfo>> getPermissionByUsername(@PathVariable("username") String username) {
        return new InvokeResult<List<PermissionInfo>>(permissionService.getPermissionByUsername(username));
    }
}
